﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class UITip : UIBase 
{
    public float destroyTime = 1f;
	private Text _txtLabel;
    private System.Action onCloseEvent;

	void Awake()
	{
		_Attach();
		_txtLabel = transform.Find("Obj/Text").GetComponent<Text>();
	}

	private void _Attach()
	{
		GameObject uiRoot = GameObject.FindGameObjectWithTag("UIRoot");
		Transform parent =  uiRoot.transform.Find("C/Tips");
		if (parent)
			CHelper.Attach(parent, transform);
	}	
	
	void Finish()
	{
		Invoke("DoDestroy", destroyTime);
        
	}

	private void DoDestroy()
	{
        if (onCloseEvent != null) onCloseEvent();
        DestroyObject(gameObject);
	}

	public void Show(string txt,System.Action onClose)
	{
		if (_txtLabel)
			_txtLabel.text = txt;

        onCloseEvent = onClose;
        Finish();
    }
}
